package com.ss.user.dao.impl;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Component;

import com.ss.user.dao.AuthorityDao;
import com.ss.user.pojo.Authority;
/**
 * 功能管理dao借口
 *
 */
@Component("authorityDao")
public class AuthorityDaoImpl  extends SqlMapClientDaoSupport implements AuthorityDao{
	/**
	 * 新增功能
	 * @param authority
	 * @author zhuchao
	 */
	@Override
	public void addAuthority(Authority authority) {
		this.getSqlMapClientTemplate().insert("authority.addAuthority", authority);
	}
	/**
	 * 更新功能
	 * @param authority
	 * @author zhuchao
	 */
	@Override
	public void updateAuthority(Authority authority) {
		this.getSqlMapClientTemplate().update("authority.updateAuthority", authority);
	}
	/**
	 * 查询功能
	 * @param authority
	 * @return
	 *  @author zhuchao
	 */
	@Override
	public Authority queryAuthority(Authority authority) {
		int totalRecord=0;
		if(authority.pageResult.getIsPaging()){
			Object obj=this.getSqlMapClientTemplate().queryForObject("authority.getAuthorityCount",authority);
			totalRecord=Integer.parseInt(obj.toString());
			authority.pageResult.setTotalRecord(totalRecord);
		}
		if(totalRecord>0 || !authority.pageResult.getIsPaging()){			
			authority.pageResult.setList(this.getSqlMapClientTemplate().queryForList("authority.getAuthority",authority));
		}
		return authority;
	}
	/**
	 * 查询功能，根据ID
	 * @param id
	 * @return
	 * @author zhuchao
	 */
	@Override
	public Authority queryAuthorityByID(String id) {
		return (Authority) this.getSqlMapClientTemplate().queryForObject("authority.getAuthorityById",id);
	}
	/**
	 * 查询角色已有功能
	 * @param id
	 * @return
	 * @author zhuchao
	 */
	@Override
	public List<Authority> queryAuthorityYes(String id) {
		return this.getSqlMapClientTemplate().queryForList("authority.queryAuthorityYes",id);
	}
	/**
	 * 查询角色没有功能
	 * @param id
	 * @return
	 * @author zhuchao
	 */
	@Override
	public List<Authority> queryAuthorityNo(String id) {
		return this.getSqlMapClientTemplate().queryForList("authority.queryAuthorityNo",id);
	}
	
	
}
